Return to start page
Core/Interface/Library Camera.j
1 library ALibraryCoreInterfaceCamera requires ALibraryCoreGeneralPlayer, ALibraryCoreMathsPoint
2
3 /**
4 * Similar to @function RotateCameraAroundLocBJ but does not use location.
5 * @author Tamino Dauth
6 * @state untested
7 */
8 function RotateCameraAroundPointForPlayer takes player user, real x, real y, real degrees, real duration returns nothing
9 local player localPlayer = GetLocalPlayer()
10 if (localPlayer == user) then
11 call SetCameraRotateMode(x, y, bj_DEGTORAD * degrees, duration)
12 endif
13 set localPlayer = null
14 endfunction
15
16 /**
17 * Similar to @function SmartCameraPanBJ but does not use location and uses Z value.
18 * Does not use z!
19 * @author Tamino Dauth
20 * @state untested
21 */
22 function SmartCameraPanWithZForPlayer takes player user, real x, real y, real zOffset, real duration returns nothing
23 local player localPlayer = GetLocalPlayer()
24 local real distance
25 if (localPlayer == user) then
26 set distance = GetDistanceBetweenPoints(x, y, 0.0, GetCameraTargetPositionX(), GetCameraTargetPositionY(), 0.0)
27 if (distance >= bj_SMARTPAN_TRESHOLD_SNAP) then
28 //If the user is too far away, snap the camera.
29 call PanCameraToTimedWithZ(x, y, zOffset, 0.0)
30 elseif (distance >= bj_SMARTPAN_TRESHOLD_PAN) then
31 //If the user is moderately close, pan the camera.
32 call PanCameraToTimedWithZ(x, y, zOffset, duration)
33 //else
34 // User is close enough, so don't touch the camera.
35 endif
36 endif
37 set localPlayer = null
38 endfunction
39
40 /**
41 * Similar to @function SmartCameraPanBJ but does not use location.
42 * @author Tamino Dauth
43 * @state untested
44 */
45 function SmartCameraPanForPlayer takes player user, real x, real y, real duration returns nothing
46 local player localPlayer = GetLocalPlayer()
47 local real distance
48 if (localPlayer == user) then
49 set distance = GetDistanceBetweenPoints(x, y, 0.0, GetCameraTargetPositionX(), GetCameraTargetPositionY(), 0.0)
50 if (distance >= bj_SMARTPAN_TRESHOLD_SNAP) then
51 //If the user is too far away, snap the camera.
52 call PanCameraToTimed(x, y, 0.0)
53 elseif (distance >= bj_SMARTPAN_TRESHOLD_PAN) then
54 //If the user is moderately close, pan the camera.
55 call PanCameraToTimed(x, y, duration)
56 //else
57 // User is close enough, so don't touch the camera.
58 endif
59 endif
60 set localPlayer = null
61 endfunction
62
63 /**
64 * Similar to @function SmartCameraPanForPlayer but does not use one single player.
65 * @author Tamino Dauth
66 * @state untested
67 */
68 function SmartCameraPan takes real x, real y, real duration returns nothing
69 local player user
70 local integer i = 0
71 loop
72 exitwhen (i == bj_MAX_PLAYERS)
73 set user = Player(i)
74 if (IsPlayerPlayingUser(user)) then
75 call SmartCameraPanForPlayer(user, x, y, duration)
76 endif
77 set user = null
78 set i = i + 1
79 endloop
80 endfunction
81
82 /**
83 * Similar to @function PanCameraToTimedLocWithZForPlayer but does not use location.
84 * @author Tamino Dauth
85 * @state untested
86 */
87 function PanCameraToTimedWithZForPlayer takes player user, real x, real y, real zOffset, real duration returns nothing
88 local player localPlayer = GetLocalPlayer()
89 if (localPlayer == user) then
90 call PanCameraToTimedWithZ(x, y, zOffset, duration)
91 endif
92 set localPlayer = null
93 endfunction
94
95 function SetCameraBoundsForPlayer takes player user, real x1, real y1, real x2, real y2, real x3, real y3, real x4, real y4 returns nothing
96 local player localPlayer = GetLocalPlayer()
97 if (user == localPlayer) then
98 call SetCameraBounds(x1, y1, x2, y2, x3, y3, x4, y4)
99 endif
100 set localPlayer = null
101 endfunction
102
103 function SetCameraBoundsToPointForPlayer takes player user, real x, real y returns nothing
104 call SetCameraBoundsForPlayer(user, x, y, x, y, x, y, x, y)
105 endfunction
106
107 function ResetCameraBoundsToMapRectForPlayer takes player user returns nothing
108 local real minX = GetRectMinX(bj_mapInitialCameraBounds)
109 local real minY = GetRectMinY(bj_mapInitialCameraBounds)
110 local real maxX = GetRectMaxX(bj_mapInitialCameraBounds)
111 local real maxY = GetRectMaxY(bj_mapInitialCameraBounds)
112 call SetCameraBoundsForPlayer(user, minX, minY, minX, maxY, maxX, maxY, maxX, minY)
113 endfunction
114
115 /// @todo Desynchronization!
116 function GetCameraTargetPositionOfPlayer takes player user returns location
117 local player localPlayer = GetLocalPlayer()
118 local location cameraTargetPosition = null
119 if (user == localPlayer) then
120 set cameraTargetPosition = GetCameraTargetPositionLoc()
121 endif
122 set localPlayer = null
123 return cameraTargetPosition
124 endfunction
125
126 /// @todo Desynchronization!
127 function GetCameraTargetPositionXOfPlayer takes player user returns real
128 local player localPlayer = GetLocalPlayer()
129 local real value = 0.0
130 if (user == localPlayer) then
131 set value = GetCameraTargetPositionX()
132 endif
133 set localPlayer = null
134 return value
135 endfunction
136
137 /// @todo Desynchronization!
138 function GetCameraTargetPositionYOfPlayer takes player user returns real
139 local player localPlayer = GetLocalPlayer()
140 local real value = 0.0
141 if (user == localPlayer) then
142 set value = GetCameraTargetPositionY()
143 endif
144 set localPlayer = null
145 return value
146 endfunction
147
148 /// @todo Desynchronization!
149 function GetCameraTargetPositionZOfPlayer takes player user returns real
150 local player localPlayer = GetLocalPlayer()
151 local real value = 0.0
152 if (user == localPlayer) then
153 set value = GetCameraTargetPositionZ()
154 endif
155 set localPlayer = null
156 return value
157 endfunction
158
159 /// @todo Desynchronization!
160 function GetCameraFieldOfPlayer takes player user, camerafield cameraField returns real
161 local player localPlayer = GetLocalPlayer()
162 local real cameraFieldValue = 0.0
163 if (user == localPlayer) then
164 set cameraFieldValue = GetCameraField(cameraField)
165 endif
166 set localPlayer = null
167 return cameraFieldValue
168 endfunction
169
170 endlibrary